#pragma once
#include <mutex>
#include "CLComSequence.h"
#include "CAttribute.h"
#include "CLComLibrarys_global.h"
//CLCOMLIBRARYS_EXPORT

class CLCOMLIBRARYS_EXPORT CCanRecordInfobase
{
public:
    CCanRecordInfobase(CLComString pathName);
	virtual ~CCanRecordInfobase();
	void Release();

public:
	static void Copy(CCanRecordInfobase* pdst,
		const CCanRecordInfobase* psrc);

public:
    void RegisterAttribute(CLComString key, ECLCOMVALUE_TYPE type);
    int ModifyAttribute(CLComValue& item);
    void GetAttributes(map<string, CLComValue>& outAttributes) const;
    int GetAttribute(CLComValue& item) const;
	void ClearAttributes();
    void LoadAttriFromFile(CLComString fileName);
    void LoadSequenceFromFile(CLComString fileName, CLComString seID);

public:
    void CreateSequence(CLComString seID);

    void AddItem(CLComString seid, CLComString id);
    CLComString GetFirstItem(CLComString seid);
    CLComString GetNextItem(CLComString seid, CLComString currentid);
    CLComString GetPrevItem(CLComString seid, CLComString currentid);
    int InsertItemBack(CLComString seid,CLComString id, const CLComValue item,
        CLComString preID);
    void DelItem(CLComString seid, CLComString id);

    int MoveUP(CLComString seid, CLComString currentid);
    int MoveDown(CLComString seid, CLComString currentid);
    void Move2Next(CLComString seid, CLComString frontID, CLComString currentid);
    void Move2Front(CLComString seid, CLComString nextID, CLComString currentid);

    void MoveUP(CLComString seid, CLComString startID, CLComString endID);
    void MoveDown(CLComString seid, CLComString startID, CLComString endID);
    void Move2Next(CLComString seid, CLComString frontID, CLComString startID, CLComString endID);
    void Move2Front(CLComString seid, CLComString nextID, CLComString startID, CLComString endID);

public:
    bool GoBackSe(CLComString seid, int nIndex = -1);
    bool GoNextSe(CLComString seid, int nIndex = -1);
    int  BackUpSe(CLComString seid, CRecordItem& recordinfo);

	bool GoBackAttribute(int nIndex = -1);
	bool GoNextAttribute(int nIndex = -1);
	int  BackUpAttribute(CRecordItem& recordinfo);
public:
	void Update();

	void ClearBackup();
	void Save2File(FILE* file);

protected:
	void CopyAttributes(const CCanRecordInfobase* pSrc);

    int ModifyAttributeInt(const CLComString& key, long long value);
    int ModifyAttributeDouble(const CLComString& key, double value);
    int ModifyAttributeString(const CLComString& key, const CLComString& value);
    int ModifyAttributeObject(const CLComString& key, void* value, long long len);

    long long GetAttributeInt(CLComString key);
    CLComString GetAttributeString(CLComString key);
    double GetAttributeDouble(CLComString key);
    long long GetAttributeObj(CLComString key, void** obj);

private:
    CLComSequence* GetSequence(CLComString key);

private:
	void ReleaseAttribute();
	void ReleaseSequence();

private:
	void CreateAttributePath();
	void CreateSequencePath();
    CLComString CreateMemberPath(CLComString path, CLComString pathName);

private:
    mutex                           m_lockSetion;
    map<CLComString, CLComSequence*>	m_mapSequences;
	CAttribute*						m_pAttribute;
    CLComString						m_attPathName;
    CLComString						m_sePathName;
    CLComString						m_PathName;
};


